<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>键盘事件</title>
</head>
<body>
<!--onkeydown	当按下按键时运行脚本。-->
<!--onkeyup	当松开按键时运行脚本。-->
<script>
    window.onkeydown = function () {
        console.log("按下按键")
        console.log("------")
    };

    window.onkeyup = function () {
        console.log("松开按键")
        console.log("------")
    };
</script>
</body>
</html>